/**
 * @防抖 在指定时间到期后执行，防止高频重复执行
 */
export const debounce = (fn, delay = 600) => {
  let timer = null;

  return function (...args) {
    let self = this;

    if (timer) {
      clearTimeout(timer);
    }

    timer = setTimeout(() => {
      fn.apply(self, args);
    }, delay);
  };
};

/**
 * @节流 在指定时间只执行一次
 */
export const throttle = (fn, gapTime = 600) => {
  let _lastTime = null;

  return function (...args) {
    let _nowTime = +new Date();

    if (!_lastTime || _nowTime - _lastTime > gapTime) {
      fn.apply(this, args);
      _lastTime = _nowTime;
    }
  };
};

export const getNavbarTitleHeight = (titleHeight = 88, searchHeight = 56) => {
  const {
    offsetTop
  } = getBounceOffset(titleHeight);
  const fixedBottom = 12;

  return titleHeight + searchHeight + offsetTop + fixedBottom;
}

/**
 * 获取标头相对胶囊偏移量
 * @param titleHeight
 * @returns
 */
export const getBounceOffset = (titleHeight) => {
  const systemInfo = getDeviceConfig();
  const menuButton = wx.getMenuButtonBoundingClientRect();

  const {
    windowScale,
    windowWidth
  } = systemInfo;
  const {
    height,
    top,
    right,
    width
  } = menuButton;

  const bounceRight = windowWidth - right;

  const offsetTop =
    (top - (titleHeight / windowScale - height) / 2) * windowScale;
  const offsetRight = (bounceRight + width) * windowScale + 8;

  return {
    offsetTop: offsetTop,
    offsetRight,
    width: width * windowScale,
    height: height * windowScale
  };
};

/**
 * 获取系统设备信息
 * @returns
 */
export const getDeviceConfig = () => {
  const systemInfo = wx.getSystemInfoSync();

  const {
    deviceId,
    deviceType,
    devicePixelRatio,
    platform,
    appId,
    appName,
    appVersion,
    windowWidth,
    windowHeight,
    screenHeight,
    screenWidth
  } = systemInfo;

  const windowScale = 750 / windowWidth;
  let system = systemInfo.system;

  if (systemInfo.system.toLowerCase().indexOf("android") >= 0) {
    system = "android";
  } else if (systemInfo.system.toLowerCase().indexOf("ios") >= 0) {
    system = "ios";
  }

  let isPc = false;
  if (
    platform.toLowerCase().indexOf("windows") >= 0 ||
    platform.toLowerCase().indexOf("mac") >= 0
  ) {
    isPc = true;
  }

  let isDevtools = false;
  if (platform.toLowerCase().indexOf("devtools") >= 0) {
    isDevtools = true;
  }

  return {
    deviceId,
    deviceType,
    devicePixelRatio,
    system,
    platform,
    isPc,
    isDevtools,
    appId,
    appName,
    appVersion,
    windowWidth,
    windowHeight,
    windowScale,
    screenHeight,
    screenWidth
  };
};

/**
 * @将字符串转换为日期对象
 * 注：ios不支持 yyyy-MM-dd 字符串转换为日期类型，需要转换为yyyy/MM/dd
 */
export const convertDateTime = (value) => {
  try {
    if (value) {
      let date;

      if (typeof value === "string") {
        const filterValue = value
          .replace(/-/g, "/")
          .replace(/年/g, "/")
          .replace(/月/g, "/")
          .replace(/日/g, "")
          .replace(/时/g, ":")
          .replace(/分/g, ":")
          .replace(/秒/g, "");

        date = new Date(filterValue);
      } else {
        date = new Date(value);
      }

      if (date) {
        return date;
      }
    }

    return new Date();
  } catch (e) {
    return new Date();
  }
};

/**
 * @把日期对象转换为指定的格式
 */
export const formatDateTime = (value, format) => {
  let date;

  if (value) {
    if (typeof value === "object") {
      date = value;
    } else {
      date = convertDateTime(value);
    }
  } else {
    date = new Date();
  }

  const options = {
    "M+": date.getMonth() + 1,
    "d+": date.getDate(),
    "h+": date.getHours(),
    "m+": date.getMinutes(),
    "s+": date.getSeconds(),
    "q+": Math.floor((date.getMonth() + 3) / 3),
    S: date.getMilliseconds(),
  };

  if (/(y+)/.test(format)) {
    format = format.replace(
      RegExp.$1,
      (date.getFullYear() + "").substr(4 - RegExp.$1.length)
    );
  }

  for (var k in options) {
    if (new RegExp("(" + k + ")").test(format)) {
      format = format.replace(
        RegExp.$1,
        RegExp.$1.length == 1 ?
        options[k] :
        ("00" + options[k]).substr(("" + options[k]).length)
      );
    }
  }

  return format;
};

/**
 * @裁剪字符显示长度 中文作为2个字符长度
 * @param str
 * @param cutLength
 * @param subfix
 * @returns
 */
export const cutStringValue = (
  str,
  cutLength = 5,
  subfix = "..."
) => {
  const splits = str.split("");

  let result = "";
  let len = 0;
  for (let char of splits) {
    if (/[\u4e00-\u9fff]/.test(char)) {
      len = len + 2;
    } else {
      len = len + 1;
    }
    if (len > cutLength) {
      result = result + subfix;
      break;
    } else {
      result = result + char;
    }
  }

  return result;
};

/**
 * @获取字符串长度 中文字算2个
 * @param {*} str 
 */
export const getStringLength = (str = "") => {
  const splits = str.split("");

  let len = 0;
  for (let char of splits) {
    if (/[\u4e00-\u9fff]/.test(char)) {
      len = len + 2;
    } else {
      len = len + 1;
    }
  }

  return len;
}

/**
 * @获取秒数
 * @param {*} timeStr mm:ss or hh:mm:ss
 */
export const getSecondsCount = (timeStr) => {
  return;
}

/**
 * @保存文件到临时目录
 * @param {*} filePath 
 * @param {*} fileName 
 */
export const saveFileTempPath = (filePath, fileName) => {
  const userPath = `${wx.env.USER_DATA_PATH}/${fileName}`;
  const fs = wx.getFileSystemManager();

  const savedFilePath = fs.saveFileSync(
    filePath,
    userPath
  );
  console.log(savedFilePath);

  return savedFilePath;
}

/**
 * @保存文件
 * @param {*} filePath 
 * @param {*} fileName 
 */
export const saveFileToDisk = (filePath, fileName, forceSave = false) => {
  return new Promise(resolve => {
    console.log(fileName);

    let savedFilePath;

    if (!forceSave) {
      savedFilePath = saveFileTempPath(filePath, fileName);
    } else {
      savedFilePath = filePath;
    }

    console.log(savedFilePath);

    const {
      isPc,
      isDevtools
    } = getDeviceConfig();

    if (isDevtools) {
      wx.showToast({
        title: "请在真机环境下预览下载功能",
        icon: "none"
      })
    } else if (isPc) {
      wx.saveFileToDisk({
        filePath: savedFilePath,
        complete: () => {
          resolve({
            status: true,
            savedFilePath: savedFilePath
          })
        }
      })
    } else {
      wx.shareFileMessage({
        filePath: savedFilePath,
        complete: () => {
          resolve({
            status: true,
            savedFilePath: savedFilePath
          })
        }
      })
    }
  })
}

/**
 * @微信版本对比
 * @param {*} v1 
 * @param {*} v2 
 */
export function compareVersion(v1, v2) {
  v1 = v1.split('.')
  v2 = v2.split('.')
  const len = Math.max(v1.length, v2.length)

  while (v1.length < len) {
    v1.push('0')
  }
  while (v2.length < len) {
    v2.push('0')
  }

  for (let i = 0; i < len; i++) {
    const num1 = parseInt(v1[i])
    const num2 = parseInt(v2[i])

    if (num1 > num2) {
      return 1
    } else if (num1 < num2) {
      return -1
    }
  }
  return 0
}

/**
 * @获取当前第几周
 * @param {*} dateTime 
 */
export const getWeekNum = (dateTime) => {
  if (!dateTime) {
    dateTime = new Date();
  }

  let temptTime = convertDateTime(dateTime);
  //周几
  let weekday = temptTime.getDay() || 7
  //周1+5天=周六
  temptTime.setDate(temptTime.getDate() - weekday + 1 + 5)
  let firstDay = new Date(temptTime.getFullYear(), 0, 1)
  let dayOfWeek = firstDay.getDay()
  let spendDay = 1
  if (dayOfWeek != 0) {
    spendDay = 7 - dayOfWeek + 1
  }
  firstDay = new Date(temptTime.getFullYear(), 0, 1 + spendDay)
  let d = Math.ceil((temptTime.valueOf() - firstDay.valueOf()) / 86400000)
  let result = Math.ceil(d / 7)
  return result + 1
}

/**
 * @获取当前周第一天
 * @param {*} dateTime 
 */
export const getWeekStartDate = (dateTime) => {
  if (!dateTime) {
    dateTime = new Date();
  }
  const now = convertDateTime(dateTime);
  let nowDayOfWeek = now.getDay() // 本周的第几天
  if (nowDayOfWeek == 0) {
    nowDayOfWeek = 7
  }
  let nowDay = now.getDate() // 当前日
  let nowMonth = now.getMonth() // 当前月
  let nowYear = now.getFullYear() // 当前年

  let weekStartDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek + 1)
  return formatDateTime(weekStartDate, "yyyy-MM-dd")
}

/**
 * @获取音量分贝
 * @param {*} arrayBuffer 
 */
export function getVolume(arrayBuffer) {
  // 将arrayBuffer转换为Float32Array，以便于计算
  var data = new Float32Array(arrayBuffer);

  // 计算平均平方
  var sumSquares = 0;
  for (var i = 0; i < data.length; i++) {
    sumSquares += data[i] * data[i];
  }
  var rms = Math.sqrt(sumSquares / data.length);

  // 将振幅转换为分贝
  return 20 * Math.log10(rms);
}

/**
 * @获取当前周最后一天
 * @param {*} dateTime 
 */
export const getWeekEndDate = (dateTime) => {
  if (!dateTime) {
    dateTime = new Date();
  }
  const now = convertDateTime(dateTime);
  let nowDayOfWeek = now.getDay() // 本周的第几天
  if (nowDayOfWeek == 0) {
    nowDayOfWeek = 7
  }
  let nowDay = now.getDate() // 当前日
  let nowMonth = now.getMonth() // 当前月
  let nowYear = now.getFullYear() // 当前年

  let weekEndDate = new Date(nowYear, nowMonth, nowDay + (7 - nowDayOfWeek));
  return formatDateTime(weekEndDate, "yyyy-MM-dd");
}

/**
 * @获取当前周第五天
 * @param {*} dateTime 
 */
export const getWeekFriDate = (dateTime) => {
  if (!dateTime) {
    dateTime = new Date();
  }
  const now = convertDateTime(dateTime);
  let nowDayOfWeek = now.getDay() // 本周的第几天
  if (nowDayOfWeek == 0) {
    nowDayOfWeek = 7
  }
  let nowDay = now.getDate() // 当前日
  let nowMonth = now.getMonth() // 当前月
  let nowYear = now.getFullYear() // 当前年

  let weekEndDate = new Date(nowYear, nowMonth, nowDay + (7 - nowDayOfWeek) - 2);
  return formatDateTime(weekEndDate, "yyyy-MM-dd");
}

/**
 * @获取路由的参数值
 * @param url
 * @param name
 * @returns
 */
export function getUrlParam(url, name) {
  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  var search = url.split("?")[1] || "";

  var r = search.match(reg);
  if (r != null) {
    return decodeURI(r[2]);
  }
  return "";
}

export function getUrlParams(url) {
  const query = url.split("?");
  const paramStr = query[1];
  if (paramStr) {
    try {
      const result = {};
      const paramSplit = paramStr.split("&");
      paramSplit.forEach(param => {
        const item = param.split("=");
        result[item[0]] = item[1]
      })

      return result;
    } catch (e) {
      return null;
    }
  }

  return null;
}

/**
 * @获取url的query转成对象的数据
 * @param {*} url 
 */
export function transformUrlQuery2Obj(url) {
  const index = url.indexOf('?');
  const obj = {};

  let queryStr = "";
  if (index !== -1) {
    queryStr = url.slice(index + 1);
  } else {
    queryStr = url;
  }

  if (!queryStr) return obj;

  const arr = queryStr.split('&');
  for (let item of arr) {
    const keyValue = item.split('=');
    obj[keyValue[0]] = keyValue[1]
  }
  return obj;
}

/**
 * @获取obj转换的urlQuery
 * @param {*} obj 
 */
export function transformObj2UrlQuery(obj) {
  if (!obj) {
    return "";
  }

  let resultList = [];
  Object.keys(obj).forEach(key => {
    if (obj[key] === null || obj[key] === undefined || obj[key] === "") {
      resultList.push(`${key}=`);
    } else {
      resultList.push(`${key}=${obj[key]}`);
    }
  })

  return resultList.join("&");
}

/**
 * @获取上一个页面的页面名称
 */
export const getPrePageName = () => {
  const pages = getCurrentPages();

  let pageName = "";
  if (pages.length > 1) {
    const prePage = pages[pages.length - 2];

    pageName = getPageNameByRoute(prePage.route, prePage.options);
  } else {
    let options = wx.getEnterOptionsSync();

    if (!options) {
      options = wx.getLaunchOptionsSync();
    }

    const scene = (options && options.scene) ? options.scene : 1001;

    pageName = getSceneName(scene);

  }

  return pageName;
}

/**
 * @通过路由名称获取页面名称
 * @param {*} route 
 */
export const getPageNameByRoute = (route, options) => {
  let pageName = "首页";

  //后续自行可补充
  switch (route) {
    case "pages/home/index":
      pageName = "首页";
      break;
    case "pages/firstColumn/index":
      pageName = "解读";
      break;
    case "pages/meeting/index":
      pageName = "活动";
      break;
    case "pages/team/index":
      pageName = "团队";
      break;
    case "pages/personal/index":
      pageName = "我的";
      break;
    case "pages/noticeMessage/index":
      pageName = "通知中心";
      break;
    case "pages/reportList/index":
      pageName = "研报";
      break;
    case "/pages/noMornDetail/index":
      pageName = "周报详情";
      break;
    case "pages/mornDetail/index":
      pageName = "日报详情";
      break;
    case "pages/point/sub/index":
      const {
        type = "week"
      } = options;
      if (type === "year") {
        pageName = "年度观点";
      } else if (type === "halfYear") {
        pageName = "半年度观点";
      } else if (type === "season") {
        pageName = "季度观点";
      } else if (type === "week") {
        pageName = "周度观点";
      } else {
        pageName = "周度观点";
      }
      break;
    case "pages/meetDetail/index":
      pageName = "会议详情";
      break;
    case "pages/teamInfo/index":
      pageName = "研究员详情";
      break;
    case "pages/selectTeam/index":
      pageName = "选择研究员";
      break;
    case "pages/personalCenter/index":
      pageName = "个人中心";
      break;
    case "pages/rpa/index":
      pageName = "rpa";
      break;
    case "pages/rpaCollection/collection":
    case "pages/rpaCollection/index":
      pageName = "rpa列表";
      break;
    case "pages/rpa/manage/index":
      pageName = "rpa触发管理";
      break;
    case "pages/myyuyue/index":
      pageName = "我的预约";
      break;
    case "pages/LongPicture/index":
      pageName = "我的长图";
      break;
    case "pages/trendsList/index":
      pageName = "我的动态";
      break;
    case "pages/previewDetail/index":
      pageName = "动态详情";
      break;
    case "pages/hotTrendsJinshi/index":
      pageName = "快评动态";
      break;
    case "pages/trendInfo/index":
      const {
        tabactive
      } = options;
      if (tabactive === "duoyuan") {
        pageName = "多元信号";
      } else if (tabactive === "jinshi") {
        pageName = "快讯详情";
      } else {
        pageName = "动态详情";
      }
      break;
    case "packageA/pages/columnSearch/index":
      pageName = "首页搜索";
      break;
    case "packageA/pages/columnSearchList/index":
      pageName = "首页搜索更多";
      break;
    case "pages/share/index":
      pageName = "分享列表";
      break;
    case "pages/columnList/index":
      pageName = options.columnName ? options.columnName : "长图列表";
      break;
    case "pages/topicDetail/index":
      pageName = getBusinessPageName();
      break;
    default:
      pageName = "首页";
      break;
  }

  return pageName;
}

/**
 * @获取时间秒数
 * @param {*} timeStr ss or mm:ss or hh:mm:ss
 */
export const getTimeSeconds = (timeStr) => {
  const timeSplits = timeStr.split(":");

  let seconds = 0;
  if (timeSplits.length === 3) {
    const hour = Number(timeSplits[0]);
    const minute = Number(timeSplits[1]);
    const second = Number(timeSplits[2]);

    seconds = second + minute * 60 + hour * 60 * 60;
  } else if (timeSplits.length === 2) {
    const minute = Number(timeSplits[0]);
    const second = Number(timeSplits[1]);

    seconds = second + minute * 60;
  } else if (timeSplits.length === 1) {
    const second = Number(timeSplits[0]);

    seconds = second;
  }

  return seconds;
}

/**
 * @获取时间字符串
 * @param {*} timeSeconds 
 */
export const getTimeStr = (timeSeconds) => {
  let secondStr = "00";
  let minuteStr = "00";
  let hourStr = "00";

  if (timeSeconds >= 60) {
    if (timeSeconds >= 60 * 60) {
      const hours = Math.floor(timeSeconds / 60 / 60);
      hourStr = fixedZero(hours);

      timeSeconds = timeSeconds - hours * 3600;

      if (timeSeconds >= 60) {
        const minutes = Math.floor(timeSeconds / 60);
        minuteStr = fixedZero(minutes);

        timeSeconds = timeSeconds - minutes * 60;

        const seconds = timeSeconds;
        secondStr = fixedZero(seconds);
      }
    } else {
      const minutes = Math.floor(timeSeconds / 60);
      minuteStr = fixedZero(minutes);

      timeSeconds = timeSeconds - minutes * 60;

      const seconds = timeSeconds;
      secondStr = fixedZero(seconds);
    }
  } else {
    const seconds = timeSeconds;
    secondStr = fixedZero(seconds);
  }

  return hourStr + ":" + minuteStr + ":" + secondStr;
}

/**
 * @获取匹配的字符数量
 * @param {*} str 
 * @param {*} charToFind 
 */
export const getStringMatchs = (str, charToFind) => {
  const regex = new RegExp(charToFind, 'g');
  let results = [];
  let match;

  while ((match = regex.exec(str))) {
    results.push({
      start: match.index,
      end: match.index + charToFind.length,
      str: charToFind,
      length: charToFind.length,
      text: str
    });
  }

  return results;
}

/**
 * @是否是空值
 * @param {*} v 
 */
export const isCellEmpty = (v) => {
  return v === null || v === undefined;
}

/**
 * @H5页面获取业务逻辑的上一个页面
 */
const getBusinessPageName = () => {
  const pages = getCurrentPages();

  const currentPage = pages[pages.length - 1];

  let pageName = "";
  //补充各自逻辑
  switch (currentPage.route) {
    case "pages/point/sub/index":
      pageName = "首页banner";
      break;
  }

  return pageName;
}

/**
 * @获取场景名称
 * @param {*} scene 
 */
const getSceneName = (scene) => {
  let result = "";

  //暂时这些，其它场景认为等价于直接打开小程序
  switch (scene) {
    case 1001:
    case 1089:
      result = "最近使用";
      break;
    case 1007:
    case 1008:
    case 1014:
      result = "分享/消息卡片";
      break;
    case 1011:
    case 1012:
    case 1013:
      result = "扫描二维码";
      break;
    case 1025:
    case 1031:
    case 1032:
      result = "扫描一维码";
      break;
    case 1035:
      result = "公众号菜单";
      break;
    case 1036:
      result = "APP分享卡片";
      break;
    case 1043:
      result = "公众号模板消息";
      break;
    case 1045:
    case 1046:
      result = "朋友圈广告";
      break;
    case 1047:
    case 1048:
    case 1049:
      result = "扫描小程序码";
      break;
    case 1058:
    case 1067:
      result = "公众号文章";
      break;
    case 1065:
      result = "urlScheme";
      break;
    case 1154:
      result = "朋友圈单页";
      break;
    case 1155:
      result = "朋友圈分享";
      break;
    case 1167:
      result = "H5开放标签";
      break;
    default:
      result = "首页";
      break;
  }

  return result;
}

/**
 * @异常场景回退首页处理
 */
export const errorPageHandler = () => {
  wx.hideLoading();
  const singlePage = getSinglePageFlag();

  if (singlePage) {
    wx.showToast({
      title: '该信息状态异常，请联系对口销售或研究员',
      icon: "none",
      duration: 999999999
    })
  } else {
    wx.showModal({
      content: '该信息状态异常，请联系对口销售或研究员',
      showCancel: false,
      confirmColor: "#4097FF",
      success: (res) => {
        if (res.confirm) {
          wx.switchTab({
            url: '/pages/home/index',
          })
        }
      }
    })
  }
}

/**
 * @获取是否是单页模式
 */
// export const getSinglePageFlag = () => {
//   return new Promise(resolve => {
//     setTimeout(() => {
//       const launchOptions = wx.getLaunchOptionsSync();
//       let mode = (launchOptions && launchOptions.mode) ? launchOptions.mode : "";
//       console.log("当前mode为：", mode);

//       const enterOptions = wx.getEnterOptionsSync();
//       if(enterOptions && enterOptions.mode) {
//         mode = enterOptions.mode;
//         console.log("调整mode为进行时，当前mode为：", mode);
//       }

//       resolve(mode === "singlePage" ? true : false);
//     }, 0)
//   })
// }
export const getSinglePageFlag = () => {

  const launchOptions = wx.getLaunchOptionsSync();
  let mode = (launchOptions && launchOptions.mode) ? launchOptions.mode : "";
  console.log("当前mode为：", mode);

  const enterOptions = wx.getEnterOptionsSync();
  if (enterOptions && enterOptions.mode) {
    mode = enterOptions.mode;
    console.log("调整mode为进行时，当前mode为：", mode);
  }

  return mode === "singlePage" ? true : false;
}

/**
 * @检验手机号
 * @param {*} phone 
 */
export const handleCheckPhone = (phone) => {
  if(!phone) {
    return {
      status: false,
      message: "请输入正确的手机号！"
    }
  } 
  
  const regExp = new RegExp("^1\\d{10}$");

  if (!regExp.test(phone)) {
    return {
      status: false,
      message: "请输入正确的手机号！"
    }
  }

  return {
    status: true,
    message: ""
  }
}

export const fixedZero = (v) => {
  if (v.toString().length === 1) {
    return "0" + v.toString();
  } else {
    return v.toString();
  }
}

/**
 * @获取三位分节法数字
 * @param {*} v 
 */
export const getSegmentNum = (v) => {
  if (v === null || v === undefined || v === "") return "";

  const splits = Number(v).toString().split("").reverse();

  const array = [];
  let str = "";
  splits.forEach((s, index) => {
    str += s;

    if (index === splits.length - 1 || (index + 1) % 3 === 0) {
      array.push(str);
      str = "";
    }
  })

  return array.join(",").split("").reverse().join("");
}

/**
 * @前往登录
 */
export const redirectLogin = () => {
  const route = `/` + getCurrentPages()[0].route;
  const query = transformObj2UrlQuery(getCurrentPages()[0].options);
  const redirectType = "redirectTo";
  const pageUrl = encodeURIComponent(`${route}${query ? '?' + query : ''}`);

  wx.redirectTo({
    url: `/pages/login/index?redirectType=${redirectType}&pageUrl=${pageUrl}`
  })
}

/**
 * @获取selectPicker组件日期格式的数据和规则
 * @仅针对常用的日期选择框
 */
export const getDateSelectPickerDataAndRule = () => {
  const zoom = 3;

  const yearList = [];
  const monthList = [{
      id: "01",
      name: "01月"
    },
    {
      id: "02",
      name: "02月"
    },
    {
      id: "03",
      name: "03月"
    },
    {
      id: "04",
      name: "04月"
    },
    {
      id: "05",
      name: "05月"
    },
    {
      id: "06",
      name: "06月"
    },
    {
      id: "07",
      name: "07月"
    },
    {
      id: "08",
      name: "08月"
    },
    {
      id: "09",
      name: "09月"
    },
    {
      id: "10",
      name: "10月"
    },
    {
      id: "11",
      name: "11月"
    },
    {
      id: "12",
      name: "12月"
    }
  ]
  const dayList = [{
      id: "01",
      name: "01日"
    },
    {
      id: "02",
      name: "02日"
    },
    {
      id: "03",
      name: "03日"
    },
    {
      id: "04",
      name: "04日"
    },
    {
      id: "05",
      name: "05日"
    },
    {
      id: "06",
      name: "06日"
    },
    {
      id: "07",
      name: "07日"
    },
    {
      id: "08",
      name: "08日"
    },
    {
      id: "09",
      name: "09日"
    },
    {
      id: "10",
      name: "10日"
    },
    {
      id: "11",
      name: "11日"
    },
    {
      id: "12",
      name: "12日"
    },
    {
      id: "13",
      name: "13日"
    },
    {
      id: "14",
      name: "14日"
    },
    {
      id: "15",
      name: "15日"
    },
    {
      id: "16",
      name: "16日"
    },
    {
      id: "17",
      name: "17日"
    },
    {
      id: "18",
      name: "18日"
    },
    {
      id: "19",
      name: "19日"
    },
    {
      id: "20",
      name: "20日"
    },
    {
      id: "21",
      name: "21日"
    },
    {
      id: "22",
      name: "22日"
    },
    {
      id: "23",
      name: "23日"
    },
    {
      id: "24",
      name: "24日"
    },
    {
      id: "25",
      name: "25日"
    },
    {
      id: "26",
      name: "26日"
    },
    {
      id: "27",
      name: "27日"
    },
    {
      id: "28",
      name: "28日"
    },
    {
      id: "29",
      name: "29日"
    },
    {
      id: "30",
      name: "30日"
    },
    {
      id: "31",
      name: "31日"
    }
  ]

  const nowDate = new Date();
  const year = nowDate.getFullYear();
  const disabledRule = [];

  //自己修改这里的开始和结束年份
  for (let i = year - zoom; i <= year + zoom; i++) {
    const curYear = i.toString();

    yearList.push({
      id: curYear,
      name: curYear + "年"
    })

    for (let j = 1; j <= 12; j++) {
      if (j === 2) {
        if (i % 4 === 0 && i % 100 !== 0) {

        } else {
          disabledRule.push({
            rule: {
              index: [0, 1],
              ids: [curYear, fixedZero(j)]
            },
            disabled: {
              index: [2],
              ids: ["29"]
            }
          })
        }
        disabledRule.push({
          rule: {
            index: [0, 1],
            ids: [curYear, fixedZero(j)]
          },
          disabled: {
            index: [2],
            ids: ["30"]
          }
        })
        disabledRule.push({
          rule: {
            index: [0, 1],
            ids: [curYear, fixedZero(j)]
          },
          disabled: {
            index: [2],
            ids: ["31"]
          }
        })
      } else if (j === 4 || j === 6 || j === 9 || j === 11) {
        disabledRule.push({
          rule: {
            index: [0, 1],
            ids: [curYear, fixedZero(j)]
          },
          disabled: {
            index: [2],
            ids: ["31"]
          }
        })
      }
    }
  }

  return {
    yearList,
    monthList,
    dayList,
    disabledRule
  }
}

/**
 * arrayBuffer转字符串 gbk
 * @param arr
 * @returns
 */
export function arrayBufferToString(arr) {
  if (typeof arr === "string") {
    return arr;
  }
  var dataview = new DataView(arr);
  var ints = new Uint8Array(arr.byteLength);
  for (var i = 0; i < ints.length; i++) {
    ints[i] = dataview.getUint8(i);
  }
  arr = ints;
  var str = "",
    _arr = arr;
  for (var i = 0; i < _arr.length; i++) {
    var one = _arr[i].toString(2),
      v = one.match(/^1+?(?=0)/);
    if (v && one.length == 8) {
      var bytesLength = v[0].length;
      var store = _arr[i].toString(2).slice(7 - bytesLength);
      for (var st = 1; st < bytesLength; st++) {
        store += _arr[st + i].toString(2).slice(2);
      }
      str += String.fromCharCode(parseInt(store, 2));
      i += bytesLength - 1;
    } else {
      str += String.fromCharCode(_arr[i]);
    }
  }
  return str;
}